The A/D conversion will gather the voltage from the scales as a 10 bit number. This function will convert this into a voltage and save a set of samples that can be averaged to calculate_mass, or interpreted by show_statistics.
Syntax
unsigned int * store_sample(unsigned int count, unsigned int Vss, unsigned int Vdd)
Usage
This function should be called (either directly, or by setting a flag) every time the A/D register samples the input voltage.
Input Arguments
unsigned int count. This is the 10b (0-1024) value from ADCON1 and ADCON2.
unsigned int Vss. The highest voltage that the A/D channel is recording.
unsigned int Vdd. The lowest voltage that the A/D channel is recording.
Output Arguments
None.
Return Value
unsigned int * . Once the voltage has been stored, the function returns a pointer to the value. (This is mainly for debugging purposes)
Settings and Registers
Read
None
Write
None
Operation
Using Vss and Vdd, the A/D sample is converted into a voltage. Then, the sample is stored in a circular buffer, where it can be read buy other parts of the program.
Code
unsignedint* store_sample(unsignedint count,unsignedint mVss,unsignedint mVdd){staticchar vinsert =0;unsignedint millivolts = Vdd +(Vss*count)/1024;unsignedint* retval = NULL;
ADSamples[vinsert]= millivolts;
retval =&ADSamples[vinsert];/*advance the position in the buffer, loop around at the end*/if(++vinsert >= VBUFSIZE){
vinsert =0;}return retval;}
store_sample
Owner: AlexPurpose and Documentation
The A/D conversion will gather the voltage from the scales as a 10 bit number. This function will convert this into a voltage and save a set of samples that can be averaged to calculate_mass, or interpreted by show_statistics.Syntax
unsigned int * store_sample(unsigned int count, unsigned int Vss, unsigned int Vdd)Usage
This function should be called (either directly, or by setting a flag) every time the A/D register samples the input voltage.Input Arguments
Output Arguments
Return Value
Settings and Registers
Read
Write
Operation
Using Vss and Vdd, the A/D sample is converted into a voltage. Then, the sample is stored in a circular buffer, where it can be read buy other parts of the program.Code